package cn.whut.glab.service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import cn.whut.glab.domain.Attributes;
import cn.whut.glab.domain.BD_Permission;
import cn.whut.glab.domain.TreeNode;
import cn.whut.glab.dao.PermissionDao;

public class PermissionService {

	PermissionDao dao = new PermissionDao();

	public List<TreeNode> getAllPermission() throws SQLException {
		List<BD_Permission> list = dao.getAllPermission();
		List<TreeNode> treeList = new ArrayList<TreeNode>();
		for (BD_Permission per : list) {
			TreeNode node = new TreeNode();
			Attributes attr = new Attributes();
			attr.setUrl(per.getLinkUrl());
			node.setId(per.getId());
			node.setText(per.getName());
			node.setIconCls(per.getIco());
			node.setAttributes(attr);

			node.setState("open");
			treeList.add(node);
		}
		return treeList;
	}

}
